home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Games Collection 1
/
software vault.zip
/
software vault
/
CDR10
/
SPX20.ZIP
/
SPX_DEMO.ZIP
/
DEMO02.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-09-24
|
4KB
|
164 lines
Program Demo2;
{ SPX library - Sprite demo Copyright 1993 Scott D. Ramsay }
Uses crt,spx_vga,spx_key,spx_obj,spx_img,spx_tim,spx_txt,spx_fnc;
const
path = '';
max = 10;
framerate : integer = 20; { NOT in fps! }
type
Pballs = ^Tballs;
Tballs = object(Tobjs)
width,height, { dimension of sprite }
kind, { sprite number }
ox,oy, { old position }
x,y, { new position }
dx,dy : integer; { direction }
constructor init(nx,ny,k:integer);
procedure drawitemobject;virtual;
procedure eraseitemobject;virtual;
procedure updateitemobject;virtual;
procedure calcitemobject;virtual;
end;
var
balls : array[0..2] of pointer;
pal : RGBlist;
head,
tail : plist;
procedure setup;
var
p : plist;
d : integer;
begin
openmode(3);
randomize;
setpageactive(3);
loadpcx(path+'tank.pcx');
loadvsp(path+'balls.vsp',balls);
loadcolors(path+'balls.pal',pal,256);
head := nil; tail := nil;
for d := 1 to max do
begin
new(p);
p^.item := new(Pballs,init(random(320),random(200),d mod 3));
p^.item^.powner := p;
addp(head,tail,p);
end;
fsetcolors(zdc); { all black palette }
pcopy(3,2); { copy to work page }
pcopy(3,1); { copy to visual }
fadein(40,pal);
end;
procedure placespeed(mode:objmode);
begin
case mode of
dDraw : putletter(4,4,255,st(framerate));
dErase : CopyRect(4,4,50,11,pages[3]^,pages[2]^);
dUpdate : CopyRect(4,4,50,11,pages[2]^,pages[1]^);
end;
end;
procedure animate;
var
p : pointer;
begin
setpageactive(2);
setrate(1000);
repeat
f_clk[0] := framerate;
if plus and (framerate<60)
then inc(framerate)
else
if minus and (framerate>0)
then dec(framerate);
doallitems(head,dErase);
placespeed(dErase);
if not space
then doallitems(head,dCalc);
doallitems(head,dDraw);
placespeed(dDraw);
doallitems(head,dUpdate);
placespeed(dUpdate);
repeat until (f_clk[0]=0);
until esc;
end;
(**) { Tballs methods }
constructor Tballs.init(nx,ny,k:integer);
begin
Tobjs.init;
kind := k;
x := nx; y := ny;
ox := x; oy := y;
repeat
dx := random(7)-3;
dy := random(7)-3;
until (dx<>0) and (dy<>0);
imagedims(balls[kind]^,width,height);
end;
procedure Tballs.eraseitemobject;
begin
CopyRect(ox-width shr 1,oy-height shr 1,ox+width shr 1,oy+height shr 1,pages[3]^,pages[2]^);
CopyRect(x-width shr 1,y-height shr 1,x+width shr 1,y+height shr 1,pages[3]^,pages[2]^);
end;
procedure Tballs.updateitemobject;
begin
CopyRect(ox-width shr 1,oy-height shr 1,ox+width shr 1,oy+height shr 1,pages[2]^,pages[1]^);
CopyRect(x-width shr 1,y-height shr 1,x+width shr 1,y+height shr 1,pages[2]^,pages[1]^);
end;
procedure Tballs.drawitemobject;
begin
ftput_clip(x,y,balls[kind]^,true);
end;
procedure Tballs.calcitemobject;
begin
ox := x; oy := y;
inc(x,dx); inc(y,dy);
if (x<0) or (x>319)
then dx := -dx;
if (y<0) or (y>199)
then dy := -dy;
end;
procedure showit;
begin
clrscr;
writeln('SPX library - Sprite demo');
writeln('Copyright 1993 Scott D. Ramsay');
writeln;
writeln('Keys:');
writeln(' ESC - quit demo');
writeln(' +/- - change frame speed');
writeln(' SPACE - pause ');
writeln;
write('Press SPACE to continue.');
clearbuffer;
repeat until space;
end;
begin
showit;
setup;
animate;
clean_plist(head,tail);
closemode;
end.